<!DOCTYPE html>
<html>
<include file="Public:header" />
<link href="__ACSS__/dialog.css" rel="stylesheet">
<link href="__ACSS__/plugins/validform/validform.css" rel="stylesheet">
<style>
	.form-control{ padding-left:5px;}
	.upload-warp{ position:relative;}
	.upload-btn{ position:absolute; top:0; right:0; border-radius:0;}
	
	.file-preview {border:1px solid #ddd; padding:5px; width:100%; margin-bottom:5px;}
	.file-preview-frame{ margin:8px; border:1px solid #ddd; box-shadow:1px 1px 5px 0px #a2958a; padding:6px; float:left; text-align:center; vertical-align:middle;}
	.file-preview-frame .btn{ float:right; margin-top:5px;}
	.file-preview-text{ color:#428bca; font-size:11px; text-align:center;}
</style>
  <body>
	  <div class="wrapper wrapper-content">
	  	<form role="form" class="form" action="__URL__/insertSub">
			<input type="hidden" name="create_time" value="<php>echo time();</php>">
			<input type="hidden" name="flag" value="1">
			<input type="hidden" name="purchase_store_id" id="purchase_store_id" value="<{$parent_id}>">
			<div class="form-group">
				<label class="col-sm-2 control-label">类别：</label>
				<div class="col-sm-10">
					<select class="form-control" datatype="*" onchange="changeType(this)">
						<option value="">请选择</option>
						<foreach name="list" item="list">
							<option value="<{$list.code}>"><{$list.name}></option>
						</foreach>
				    </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">产品：</label>
				<div class="col-sm-10">
					<select class="form-control purchase_product_id" datatype="*" name="purchase_product_id">
						<option value="">请选择</option>
				    </select>
				    <input type="hidden" name="name" class="name">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">库存：</label>
				<div class="col-sm-10">
					<input type="text" datatype="n" name="num" class="form-control" placeholder="库存">
				</div>
			</div>
			<div class="clearfix"></div>
			<br/>
			<div class="clearfix">
				<button type="submit" id="submit" class="btn btn-success btn-block">提交</button>
				<button type="reset" id="reset2" class="btn btn-success btn-block hidden">重置</button>
			</div>
		</form>
	  </div>
  </body>
<!-- 全局js -->
<include file="Public:foot" />
<script src="__AJSPLUGINS__/validform/Validform_v5.3.2_min.js"></script>
<script>
$(function(){
	$("#reset2").click();
	var index = parent.layer.getFrameIndex(window.name);
	var form = $(".form").Validform({
		tiptype:4,
		ajaxPost:true,
		beforeSubmit:function(curform){
			$(".name").val($(".purchase_product_id").find("option:selected").text());
		},
		callback:function(data){
			if(data.status == 1) {
				window.parent.layer.msg(data.info);
				window.parent.$('#table_list2').trigger("reloadGrid");
			}else{
				window.parent.layer.msg(data.info);
			}
			parent.layer.close(index);
		}
	});
})
function changeType(t){
	if($(t).val() == ""){return false;}
	$(".purchase_product_id").attr("disabled",true);
	$.ajax({
		url:"__URL__/getPurchase",
		type:"post",
		data:{'code':$(t).val(),'purchase_store_id':$("#purchase_store_id").val()},
		success:function(json){
			var data = eval("("+json+")");
			var html = '<option value="">请选择</option>';
			if(data.info != 0){
				for(var i=0;i<data.data.length;i++){
					html += '<option value="'+ data.data[i].id +'">'+ data.data[i].name +'</option>';
				}
			}
			$(".purchase_product_id").html(html);
			$(".purchase_product_id").attr("disabled",false);
		}
	})
}
</script>
</html>